// Loren Milliman
// TCSS 360 TeamDAMN
// For OnTrack System
// 11/24/14
package teamdamn.model;

import java.awt.Desktop;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;

import teamdamn.controller.DBIO;

/**
 * Contains a list of RFPs stored in the local respository.
 * Stores the RFPs and Notes as an array of File Objects.
 * As such standard File methods can be used: 
 * 
 * RFPList is implemented as a Singleton.
 */
public class RFPList {
	
	/** The instance of RFPList */
    private static final RFPList instance = new RFPList();
    
    private RFPList () {
    }

    /**
     * Returns the instance of RFP List
     * @return RFPList
     */
    public static RFPList getInstance() {
        return instance;
    }
    /**
     * Returns the list of RFPs
     * @author Loren, Code
     * @author Kevin, Edit
     */
    public File[] getRFPList(){
    	File directory = new File(DBIO.getInstance().getRepositoryLocation());  
    	// This can now has the correct file locations when we have jar on the same folder
    	File[] files = new File(directory.getPath()).listFiles(new Filter());
    	return files;
    }
    
    class Filter implements FileFilter  
    {  
       public boolean accept(File file)  
       {  
          return file.getName().endsWith("docx");  
       }
    }  

    /**
     * launch the provided RFP or Note
     * 
     * @param RFPName is the name of RFP or Note to be launched.
     */
    public void launchRFP(File theFile){
    	try {
    		Desktop.getDesktop().open(theFile);
//    		if (DBIO.isWindows() ) {
//            	ProcessBuilder pb = new ProcessBuilder("cmd.exe " + theFile.getAbsolutePath() );
//    			Process p = pb.start();
//    			System.out.println(theFile.getName() + " should have launched");
//    		} else {
//    			System.out.println ("Not a windows system");
//    		}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
